home *** CD-ROM | disk | FTP | other *** search
-
- #include <QDOffScreen.h>
- #include "SpriteWorldUtils.h"
- #include "SWDitherDown.h"
-
- /*
-
- If you create a game using 8-bit graphics, and you:
- A) want the game to be usable on a less-than-8-bit system, although
- B) not usable on 68000 Macs, and
- C) rather than creating new graphics for it, want to dither down the 8-bit graphics,
- then these routines will help you out.
-
- Note B) above; SpriteWorld requires Color QuickDraw, which in turn requires a 68020 or
- higher processor, so your game still won't be playable on a Mac Plus, SE, Mac Classic, etc.
- These routines use the CopyBits ditherCopy mode. This provides results far superior to
- what you get from simply using DrawPicture() to draw an 8-bit PICT to a lower-depth GWorld.
- The results are usually still pretty ugly, however.
-
- Warning! no error handling in these routines. Errors might be not enough memory
- to create the GWorlds or to load the pict/cicn or, of course, invalid resID's.
-
-
-
- DitherDownPict; use with either a Sprite made with SWCreateSpriteFromPictResource
- or with SWCreateSpriteFromSinglePict. In the case of SWCreateSpriteFromPictResource,
- pictResID is the ID of a Frame's pict, and destGWorld would be the Frame's framePort:
-
- for (frame = 0; frame < maxFrames; frame++)
- {
- theFrameP = theSprite->frameArray[frame];
-
- DitherDownPict( pictResID+frame, theFrameP->framePort );
- }
-
- For SWCreateSpriteFromSinglePict, you'd just pass the multi-frame pict's ID, and
- the shared GWorld of the Sprite:
-
- DitherDownPict( pictResID, theSprite->sharedPictGWorld );
-
- If you're dithering down tiles, you just have to call this once for a single-pict
- group of tiles. For the destGWorld, use the framePort of any one of the tiles:
-
- DitherDownPict( pictResID, theTile->framePort );
-
- */
-
- /******************** DitherDownPict ********************/
- void DitherDownPict( short pictResID, GWorldPtr destGWorld )
- {
-
- GWorldPtr picGWld,
- oldGWld;
- GDHandle oldGDH;
- Rect picRect;
- PicHandle thePic;
- GWorldFlags pixelState;
-
-
- GetGWorld( &oldGWld, &oldGDH );
-
- thePic = GetPicture( pictResID );
- picRect = (**(thePic)).picFrame;
- OffsetRect( &picRect, 0-picRect.left, 0-picRect.top );
-
- (void)NewGWorld( &picGWld, 8, &picRect, nil, nil, 0 );
- (void)LockPixels( GetGWorldPixMap( picGWld ));
- SetGWorld( picGWld, NULL );
-
- DrawPicture( thePic, &picRect );
- ReleaseResource( (Handle)thePic );
-
- pixelState = GetPixelsState( GetGWorldPixMap( destGWorld ));
- (void)LockPixels( GetGWorldPixMap( destGWorld ));
- SetGWorld( destGWorld, NULL );
- CopyBits ( (BitMap*)*GetGWorldPixMap( picGWld ),
- (BitMap*)*GetGWorldPixMap( destGWorld ),
- &picRect,
- &picRect, ditherCopy, nil);
-
- SetPixelsState( GetGWorldPixMap( destGWorld ), pixelState );
- DisposeGWorld( picGWld );
- SetGWorld( oldGWld, oldGDH );
- }
-
-
- /*
- This routine is for when you have a self-masking Sprite created from an 8-bit PICT,
- and want to use it on a lower-depth screen. Using the 8-bit PICT as a pixel mask may
- not work correctly unless you convert the mask afterwards with this. This is called
- much like DitherDownPict, except that the maskPort is passed instead of the framePort:
-
- for (frame = 0; frame < maxFrames; frame++)
- {
- theFrameP = theSprite->frameArray[frame];
-
- LowerMaskDepth( pictResID+frame, theFrameP->maskPort );
- }
- or:
- LowerMaskDepth( pictResID, theSprite->sharedMaskGWorld );
- */
-
- /******************** LowerMaskDepth ********************/
- void LowerMaskDepth( short pictResID, GWorldPtr destGWorld )
- {
- GWorldPtr picGWld,
- oldGWld;
- GDHandle oldGDH;
- Rect picRect;
- PicHandle thePic;
- GWorldFlags pixelState;
-
-
- if ( destGWorld == NULL )
- return;
-
- GetGWorld( &oldGWld, &oldGDH );
-
- thePic = GetPicture( pictResID );
- picRect = (**(thePic)).picFrame;
- OffsetRect( &picRect, 0-picRect.left, 0-picRect.top );
-
- (void)NewGWorld( &picGWld, 8, &picRect, nil, nil, 0 );
- (void)LockPixels( GetGWorldPixMap( picGWld ));
- SetGWorld( picGWld, NULL );
-
- DrawPicture( thePic, &picRect );
- ReleaseResource( (Handle)thePic );
-
- SWBlackenGWorld( picGWld );
-
- pixelState = GetPixelsState( GetGWorldPixMap( destGWorld ));
-
- (void)LockPixels( GetGWorldPixMap( destGWorld ));
- SetGWorld( destGWorld, NULL );
- CopyBits ( (BitMap*)*GetGWorldPixMap( picGWld ),
- (BitMap*)*GetGWorldPixMap( destGWorld ),
- &picRect,
- &picRect, srcCopy, nil);
- InvertRect( &picRect );
-
- SetPixelsState( GetGWorldPixMap( destGWorld ), pixelState );
-
- DisposeGWorld( picGWld );
- SetGWorld( oldGWld, oldGDH );
- }
-
-
-
- /*
- DitherDownCicn; use with a Sprite made with SWCreateSpriteFromCicnResource.
- cicnResID is the ID of a Frame's CIcon, and destGWorld is the Frame's framePort:
-
- for (frame = 0; frame < maxFrames; frame++)
- {
- theFrameP = theSprite->frameArray[frame];
-
- DitherDownCicn( cicnResID+frame, theFrameP->framePort );
- }
-
- Can also be used for tiles made from CIcons:
-
- theFrameP = mySpriteWorldP->tileFrameArray[tileID];
- DitherDownCicn( cicnResID, theFrameP->framePort );
-
- Note that this dithers down the 8-bit color image of the CIcon; it ignores the CIcon's
- black & white image, if any.
- */
-
- /******************** DitherDownCicn ********************/
- void DitherDownCicn( short cicnResID, GWorldPtr destGWorld )
- {
-
- GWorldPtr picGWld,
- oldGWld;
- GDHandle oldGDH;
- Rect frameRect;
- CIconHandle cIconH;
- GWorldFlags pixelState;
-
-
- GetGWorld( &oldGWld, &oldGDH );
-
-
- cIconH = GetCIcon( cicnResID );
-
- HLock((Handle)cIconH);
- frameRect = (**cIconH).iconPMap.bounds;
-
- (void)NewGWorld( &picGWld, 8, &frameRect, nil, nil, 0 );
- (void)LockPixels( GetGWorldPixMap( picGWld ));
- SetGWorld( picGWld, NULL );
-
- (**cIconH).iconPMap.baseAddr = *(**cIconH).iconData;
- CopyBits( (BitMap*)(&((**cIconH).iconPMap)),
- (BitMap*)*GetGWorldPixMap( picGWld ),
- &frameRect,
- &frameRect, srcCopy, nil);
- DisposeCIcon(cIconH);
-
- pixelState = GetPixelsState( GetGWorldPixMap( destGWorld ));
- (void)LockPixels( GetGWorldPixMap( destGWorld ));
- SetGWorld( destGWorld, NULL );
- CopyBits ( (BitMap*)*GetGWorldPixMap( picGWld ),
- (BitMap*)*GetGWorldPixMap( destGWorld ),
- &frameRect,
- &frameRect, ditherCopy, nil);
- SetPixelsState( GetGWorldPixMap( destGWorld ), pixelState );
-
- DisposeGWorld( picGWld );
- SetGWorld( oldGWld, oldGDH );
- }
-
-
-
-